﻿using Google.Protobuf;
using Server.Framework.Message;
using Server.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Message.Response
{
    /// <summary>
    /// Author: Leil
    /// Description: 角色列表回复消息
    /// CreateTime: 2020/5/13 12:31:32
    /// </summary>
    class UserListResp : ResponseBaseMessage
    {
        public List<UserDao> Users { get; } = new List<UserDao>();

        public int Count { get; set; }

        public UserListResp(int msgId):base(msgId)
        {

        }

        public override byte[] Serialize()
        {
            UserList msg = new UserList();
            Users.ForEach(user =>
            {
                User u = new User
                {
                    Id = user.ID,
                    OrgId = user.OrgId,
                    OrgName = user.OrgName ?? "",
                    LoginName = user.LoginName,
                    Password = user.Password,
                    Sort = user.Sort,
                    Status = user.Status,
                    Creator = user.Creator ?? "",
                    CreateTime = user.CreateTime ?? "",
                    Updator = user.Updator ?? "",
                    UpdateTime = user.UpdateTime ?? "",
                };
                u.RoleIds.AddRange(user.RoleIds);
                msg.Users.Add(u);
            });
            msg.Count = Count;
            return msg.ToByteArray();
        }
    }
}
